const http = require('http')
const server = http.createServer()
server.on('request',(req,res)=>{
    // 获取请求的 url 地址
    const url = req.url
    // 设置默认的内容为 404 Not found
    let content = '<h1>404 Not Found</h1>'
    // 用户请求的是首页
    if(url === '/'|| url === '/index.html'){
        content = '<h1>首页</h1>'
    // 用户请求的是关于页面
    }else if(url === '/about'){
        content = '<h1>关于</h1>'
    }

    res.setHeader('Content-Type','text/html; charset=utf-8')
    res.end(content)
})



server.listen('8080',()=>{
    console.log('server running at http://127.0.0.1:8080');
})